package azku.entitys;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import azku.BitmapHelper;
import azku.MyApplication;
import azku.net.HttpHelper;
import azku.photoviews.DataManager;
import azku.photoviews.DataSetting;
import azku.photoviews.R;

public class EListView {
	public static final String KEY_ID = "itemid";
	public static final String KEY_TITLE = "title";
	public static final String KEY_DATE = "date";
	public static final String KEY_IMAGEURL = "imageurl";
	public static final String KEY_DES = "des";
	public static final String KEY_GROUPID = "groupid";
	public static final String KEY_VINDEX = "vindex";
	public static final String KEY_VPOWER = "vpower";
	public static final String KEY_ASSESSCOUNT = "count";
	public static final String KEY_ASSESSSCORE = "score";
	public static final String KET_GROUPTYPENAME = "grouptypename";

	private int mID;
	private String mImgUrl;
	private String mTitle;
	private String mDate;
	private int mAssessCount;
	private String mDes;
	private Bitmap mImage;
	private int mGroupType;
	private int mScore;
	private int mVindex;
	private int mVpower;
	private String mGroupTypeName;

	public String getGroupTypeName() {
		if (mGroupTypeName == null) {
			mGroupTypeName = DataManager.It().GetGroupTypeName(
					this.getGroupType());
		}
		return mGroupTypeName;
	}

	public EListView() {
		mID = 0;
		mImgUrl = "";
		mTitle = "";
		mDate = "";
		mDes = "";
		mGroupType = 0;
		mScore = 0;
		mVindex = 0;
		mVpower = 0;
	}

	public void setID(int id) {
		mID = id;
	}

	public int getID() {
		return this.mID;
	}

	public void setImgUrl(String imgurl) {
		this.mImgUrl = imgurl;

	}

	public String getImgUrl() {
		return this.mImgUrl;
	}

	public void setTitle(String title) {
		this.mTitle = title;
	}

	public String getTitle() {
		return this.mTitle;
	}

	public void setDate(String date) {
		this.mDate = date;
	}

	public String getDate() {
		return this.mDate;
	}

	public void setAssessCount(int assess) {
		this.mAssessCount = assess;
	}

	public int getAssessCount() {
		return this.mAssessCount;
	}

	public void setDes(String des) {
		this.mDes = des;
	}

	public String getDes() {
		return this.mDes;
	}

	public Bitmap getImage() {
		if (this.mImage == null) {
			if (!this.mImgUrl.equals("")) {
				Bitmap tempImage = HttpHelper
						.GetBitmap(DataSetting.S_URL_WEBSITE + this.mImgUrl);
				this.mImage = BitmapHelper.createReflectionImageWithOrigin(BitmapHelper.getRoundedCornerBitmap(tempImage, 5.0f));
				//this.mImage = BitmapHelper.getRoundedCornerBitmap(tempImage, 5.0f);
			}
			if (this.mImage == null) {
				this.mImage = BitmapFactory.decodeResource(MyApplication
						.getInstance().getResources(), R.drawable.icon);
			}
		}
		return this.mImage;
	}

	public void setGroupType(int itype) {
		mGroupType = itype;
	}

	public int getGroupType() {
		return this.mGroupType;
	}

	public void setScore(int iscore) {
		this.mScore = iscore;
	}

	public int getScore() {
		return this.mScore;
	}

	public void setVindex(int ivindex) {
		mVindex = ivindex;
	}

	public int getVindex() {
		return this.mVindex;
	}

	public void setVpower(int ipower) {
		mVpower = ipower;
	}

	public int getVpower() {
		return this.mVpower;
	}

	public void bindParams(JSONObject obj) {
		if (obj == null)
			return;
		try {
			this.setAssessCount(obj.getInt(KEY_ASSESSCOUNT));
			this.setDate(obj.getString(KEY_DATE));
			this.setDes(obj.getString(KEY_DES));
			this.setGroupType(obj.getInt(KEY_GROUPID));
			this.setID(obj.getInt(KEY_ID));
			this.setTitle(obj.getString(KEY_TITLE));
			this.setScore(obj.getInt(KEY_ASSESSSCORE));
			this.setVindex(obj.getInt(KEY_VINDEX));
			this.setVpower(obj.getInt(KEY_VPOWER));
			this.setImgUrl(obj.getString(KEY_IMAGEURL));
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	public Map<String, Object> getMap() {
		Map<String, Object> retMap = new HashMap<String, Object>();
		retMap.put(KEY_ASSESSCOUNT, this.getAssessCount());
		retMap.put(KEY_ASSESSSCORE, this.getScore());
		retMap.put(KEY_DATE, this.getDate());
		retMap.put(KEY_DES, this.getDes());
		retMap.put(KEY_GROUPID, this.getGroupType());
		retMap.put(KEY_ID, this.getID());
		return retMap;
	}
}
